package com.molichuxing.gateway.bff.statistics.services.impl;

import com.molichuxing.framework.exception.BizException;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.framework.utils.RedisUtil;
import com.molichuxing.gateway.bff.statistics.convertor.Convert;
import com.molichuxing.gateway.bff.statistics.entity.response.*;
import com.molichuxing.gateway.bff.statistics.services.StatisticsBffService;
import com.molichuxing.gateway.property.StatisticsQueryTypeEnum;
import com.molichuxing.services.business.dto.response.*;
import com.molichuxing.services.business.service.*;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.infrastructure.service.*;
import com.molichuxing.services.property.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static com.molichuxing.gateway.exception.StatisticsRedisKey.*;

/**
 * @Author: renzhengyu
 * @Description:
 * @Date: Created in 16:09 2019/10/14
 * @Modified By:
 **/
@Service("statisticsService")
public class StatisticsBffServiceImpl implements StatisticsBffService {
    private static final Logger logger = LoggerFactory.getLogger(StatisticsBffServiceImpl.class);

    @Resource
    private GoodsService goodsService;
    @Resource
    private CarService carService;
    @Resource
    private UserDetailService userDetailService;
    @Resource
    private UserBizService userBizService;
    @Resource
    private DealerService dealerService;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private CarViolationService carViolationService;
    @Resource
    private CarBizService carBizService;
    @Resource
    private OrderBizService orderBizService;
    @Resource
    private OfflineService offlineService;
    @Resource
    private StoreService storeService;
    @Resource
    private StockCarService stockCarService;
    @Resource
    private DrivingLicenseService drivingLicenseService;
    @Resource
    private ComplaintService complaintService;
    @Resource
    private IovCarService iovCarService;
    @Resource
    private BasicdataStatisticsOrderService basicdataStatisticsOrderService;

    @Resource
    private OrderExclusivelService orderExclusivelService;

    @Resource
    private OrderSubscribeService orderSubscribeService;

    @Resource
    private VehicleService vehicleService;

    @Resource
    private RegionService regionService;

    @Resource
    private GoodsBizService goodsBizService;

    @Resource
    private VehicleBizService vehicleBizService;
    @Resource
    private StatisticsAssetService statisticsAssetService;

    /**
     * 首页订单统计
     *
     * @return
     */
    @Override
    public HomeOrderStatisticsVo getHomeOrderStatisticsVo() {
        HomeOrderStatisticsVo homeOrderStatisticsVo = new HomeOrderStatisticsVo();

        List<LocalDateTime> todaySubscribe = orderSubscribeService.getTodaySubscribeCount();

        List<LocalDateTime> todayExclusive = orderExclusivelService.getTodayExclusiveCount();

        homeOrderStatisticsVo.setTodaySubscribe(todaySubscribe == null ? 0 : todaySubscribe.size());
        homeOrderStatisticsVo.setTodayExclusive(todayExclusive == null ? 0 : todayExclusive.size());
        homeOrderStatisticsVo.setSevenDaysSubscribe(basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.SUBSCRIBE, LocalDate.now().minusDays(7), LocalDate.now().minusDays(1)));
        homeOrderStatisticsVo.setSevenDaysExclusive(basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.EXCLUSIVE, LocalDate.now().minusDays(7), LocalDate.now().minusDays(1)));
        return homeOrderStatisticsVo;
    }

    /**
     * 资源统计
     *
     * @return
     */
    @Override
    public ResourceStatisticsVo getResourceStatisticsVo() {
        ResourceStatisticsVo resourceStatisticsVo = new ResourceStatisticsVo();
        resourceStatisticsVo.setSubscribe(goodsService.getNoDeleteGoodsCount(GoodsTypeEnum.SUBSCRIBE.getValue()));
        resourceStatisticsVo.setExclusive(goodsService.getNoDeleteGoodsCount(GoodsTypeEnum.EXCLUSIVE.getValue()));
        resourceStatisticsVo.setPurchaseVehicle(carService.getNoDeleteCarCount());
        resourceStatisticsVo.setContractedUser(userDetailService.getPayUserCount());
        resourceStatisticsVo.setBusiness(dealerService.getOpenDealerCount());
        return resourceStatisticsVo;
    }


    /**
     * 订单统计
     *
     * @param map
     * @return
     */
    @Override
    public PreviousOrderStatisticsVo getOrderStatisticsVo(Map<String, Object> map) throws Exception {
        if (null == map.get("orderType")) {
            throw new Exception("缺少参数");
        }
        Integer orderType = Integer.valueOf(String.valueOf(map.get("orderType")));
        Integer queryType = Integer.valueOf(String.valueOf(map.get("queryType")));

        LocalDate startTime = null;
        LocalDate endTime = null;
        List<PieChartVo> pieChartVoList = new ArrayList<>();

        if (queryType.equals(StatisticsQueryTypeEnum.PREVIOUS.getValue())) {
            //开始时间不能大于当前时间
            if (null == map.get("startTime")) {
                throw new Exception("缺少参数");
            }
            if (null == map.get("endTime")) {
                throw new Exception("缺少参数");
            }
            startTime = DateUtil.parseDate(String.valueOf(map.get("startTime")));
            endTime = DateUtil.parseDate(String.valueOf(map.get("endTime")));
            if (startTime.equals(LocalDate.now())
                    || startTime.isAfter(LocalDate.now())) {
                throw new Exception("开始日期必须小于当前日期");
            }
            if (endTime.equals(LocalDate.now())
                    || endTime.isAfter(LocalDate.now())) {
                throw new Exception("结束日期必须小于当前日期");
            }


            List<PieChartDto> pieChartDtoList = basicdataStatisticsOrderService.getStatisticsOrderByDate(StatisticsOrderTypeEnum.getEnum(orderType), startTime, endTime);
            PieChartVo pieChartVo = null;
            if (pieChartDtoList != null && pieChartDtoList.size() > 0) {
                for (PieChartDto pieChartDto : pieChartDtoList) {
                    pieChartVo = new PieChartVo();
                    BeanUtils.copyProperties(pieChartDto, pieChartVo);
                    pieChartVoList.add(pieChartVo);

                }
            }
        } else if (queryType.equals(StatisticsQueryTypeEnum.TO_DAY.getValue())) {

            List<LocalDateTime> todayOrderStatisticsList = new ArrayList<>();
            if (orderType.equals(StatisticsOrderTypeEnum.SUBSCRIBE.getValue())) {
                todayOrderStatisticsList = orderSubscribeService.getTodaySubscribeCount();
            } else if (orderType.equals(StatisticsOrderTypeEnum.EXCLUSIVE.getValue())) {
                todayOrderStatisticsList = orderExclusivelService.getTodayExclusiveCount();
            }

            for (int i = 0; i < 24; i++) {
                LocalDateTime now = LocalDateTime.now();
                if (now.getHour() + 1 == i) {
                    pieChartVoList.add(new PieChartVo(DateUtil.formatTime(now, "HH:mm"), 0));
                    break;
                }
                pieChartVoList.add(new PieChartVo(String.format("%02d", i), 0));
            }
            for (LocalDateTime time : todayOrderStatisticsList) {
                int hour = time.getHour();
                PieChartVo vo = pieChartVoList.get(hour + 1);
                vo.setValue(vo.getValue() + 1);
            }

        }


        PreviousOrderStatisticsVo previousOrderStatisticsVo = new PreviousOrderStatisticsVo();
        //订单统计环比
        previousOrderStatisticsVo.setOrderProportion(getOrderProportion(StatisticsOrderTypeEnum.getEnum(orderType)));

        previousOrderStatisticsVo.setPieChartVoList(pieChartVoList);

        return previousOrderStatisticsVo;
    }

    /**
     * 订单地域分布统计（完成提车订单，含续订生效订单）
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<DistributionStatisticsVo> getOrderRegionalDistribution() throws Exception {
        List<DistributionStatisticsVo> result = new ArrayList<>();

        // 查询每个门店下生效订单（提车、续订生效）数量
        Map<Integer, Integer> orderStoreMap = orderBizService.getEffectiveOrderStoreStatistics();
        if (orderStoreMap == null || orderStoreMap.isEmpty()) {
            return result;
        }

        // 根据门店 ids 查询门店所属 城市
        Map<Integer, StoreDto> storeCityMap = storeService.getStoreMapByIds(new ArrayList<>(orderStoreMap.keySet()));
        if (storeCityMap == null || storeCityMap.isEmpty()) {
            return result;
        }

        // 转换数据，统计每个市的订单数量(key:城市id, value:订单数量)
        Map<Integer, Integer> orderCityMap = new HashMap<>();
        for (Integer storeId : orderStoreMap.keySet()) {
            StoreDto storeDto = storeCityMap.get(storeId);
            if (storeDto == null) {
                continue;
            }
            // 获取该门店下订单数量
            Integer orderStoreCount = orderStoreMap.getOrDefault(storeId, 0);
            Integer orderCityCount = orderCityMap.getOrDefault(storeDto.getRegionId(), 0);
            orderCityMap.put(storeDto.getRegionId(), orderStoreCount + orderCityCount);
        }
        orderStoreMap = null;
        storeCityMap = null;

        // 根据市 ids 查询市所属的省份
        Map<Integer, RegionInfoDto> cityProvMap = regionService.getRegionInfoListByIds(new ArrayList<>(orderCityMap.keySet()));
        if (cityProvMap == null || cityProvMap.isEmpty()) {
            return result;
        }
        // 转换，统计每个省有多少订单（key：省id，value：订单数量）
        Map<Integer, Integer> orderProvMap = new HashMap<>();
        for (Integer cityId : orderCityMap.keySet()) {
            RegionInfoDto prov = cityProvMap.get(cityId);
            if (prov == null) {
                continue;
            }

            Integer orderCityCount = orderCityMap.getOrDefault(cityId, 0);
            Integer orderProvCount = orderProvMap.getOrDefault(prov.getProvinceId(), 0);
            orderProvMap.put(prov.getProvinceId(), orderCityCount + orderProvCount);
        }
        orderCityMap = null;

        // 查询所有省
        List<RegionCityDto> provs = regionService.getAllCity(1);
        for (RegionCityDto prov : provs) {
            result.add(new DistributionStatisticsVo(prov.getId().toString(),
                    prov.getName(), orderProvMap.getOrDefault(prov.getId(), 0)));
        }

        return result;
    }

    /**
     * 车型销售统计（用户签约完成订单提车后（订阅包含续订支付））
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<SalesStatisticsVo> getOrderVehicleSales() throws Exception {
        List<SalesStatisticsVo> result = new ArrayList<>();

        // 查询每个车型下生效订单（提车、续订支付）数量
        Map<Integer, Integer> orderVehicleMap = orderBizService.getEffectiveOrderVehicleStatistics();
        if (orderVehicleMap == null || orderVehicleMap.isEmpty()) {
            return result;
        }
        // 查询出所有车型、品牌信息
        List<VehicleNameBizDto> vehicleNameBizDtos = vehicleService.getAllVehicleMake();
        if (vehicleNameBizDtos == null || vehicleNameBizDtos.isEmpty()) {
            return result;
        }
        for (VehicleNameBizDto vehicleNameBizDto : vehicleNameBizDtos) {
            SalesStatisticsVo vo = new SalesStatisticsVo();
            vo.setName(vehicleNameBizDto.getSeriesName() + " " + vehicleNameBizDto.getModelName());
            vo.setCity(vehicleNameBizDto.getBrandName());
            vo.setRevenue(orderVehicleMap.getOrDefault(vehicleNameBizDto.getModelId(), 0));
            vo.setLang(vo.getName() + "(" + vo.getRevenue() + "单)");
            result.add(vo);
        }

        // 排序
        result = result.stream().sorted(Comparator.comparing(SalesStatisticsVo::getRevenue).reversed())
                .collect(Collectors.toList());

        return result;
    }

    /**
     * 商品销售统计(专属、订阅)（用户签约完成支付订单，订阅包含续订支付完成订单）
     *
     * @param orderType 统计订单类型
     * @return
     * @throws Exception
     */
    @Override
    public List<SalesStatisticsVo> getOrderGoodsSales(OrderTypeEnum orderType) throws Exception {
        List<SalesStatisticsVo> result = new ArrayList<>();

        List<GoodsSalesStatisticsBizDto> goodsSalesStatisticsList = orderBizService.getEffectiveOrderGoodsStatistics(orderType);
        if (goodsSalesStatisticsList == null || goodsSalesStatisticsList.isEmpty()) {
            return result;
        }

        // 查询出所有车型、品牌信息
        List<VehicleNameBizDto> vehicleNameBizDtos = vehicleService.getAllVehicleMake();
        if (vehicleNameBizDtos == null || vehicleNameBizDtos.isEmpty()) {
            return result;
        }
        Map<Integer, VehicleNameBizDto> VehicleNameMap = vehicleNameBizDtos.stream()
                .collect(Collectors.toMap(VehicleNameBizDto::getModelId, dto -> dto));

        for (GoodsSalesStatisticsBizDto goodsSalesStatisticsBizDto : goodsSalesStatisticsList) {
            VehicleNameBizDto vehicleNameBizDto = VehicleNameMap.get(goodsSalesStatisticsBizDto.getVehicleId());
            SalesStatisticsVo vo = new SalesStatisticsVo();
//            vo.setName(vehicleNameBizDto.getSeriesName() + " " + vehicleNameBizDto.getModelName());
//            vo.setCity(vehicleNameBizDto.getBrandName());
            vo.setRevenue(goodsSalesStatisticsBizDto.getSales());
            vo.setCity(vehicleNameBizDto.getSeriesName() + " " + vehicleNameBizDto.getModelName());
            vo.setName(goodsSalesStatisticsBizDto.getGoodsName());
            vo.setLang(vo.getName() + "(" + vo.getRevenue() + "单)");

            result.add(vo);
        }

        return result;
    }

    /**
     * 订单用户画像（完成支付用户）
     *
     * @return
     * @throws Exception
     */
    @Override
    public OrderUserPortraitVo getOrderUserPortrait() throws Exception {
        OrderUserPortraitVo result = new OrderUserPortraitVo();

        UserPortraitBizDto userPortraitBizDto = userBizService.getUserPortraitVo(true);
        if (userPortraitBizDto == null) {
            logger.error("订单用户画像查询异常，查询数据为空");
            throw new BizException("订单用户画像查询异常");
        }
        List<Map<String, Object>> sexDistributionList = userPortraitBizDto.getSexDistribution();
        if (sexDistributionList == null) {
            logger.error("订单用户画像查询异常，性别分布为空");
            throw new BizException("订单用户画像查询异常");
        }
        List<PieChartVo> sexDistribution = new ArrayList<>();
        for (Map<String, Object> map : sexDistributionList) {
            Object obj = map.get("key");
            Long k = obj == null ? null : Long.parseLong(String.valueOf(obj));
            if (k == null) {
                continue;
            }
            String key = k == 0L ? "女性" : "男性";
            obj = map.get("value");
            Integer value = obj == null ? 0 : Integer.parseInt(String.valueOf(obj));
            sexDistribution.add(new PieChartVo(key, value));
        }
        result.setSexDistribution(sexDistribution);

        List<Map<String, Object>> ageDistributionList = userPortraitBizDto.getAgeDistribution();
        if (ageDistributionList == null) {
            logger.error("订单用户画像查询异常，年龄分布为空");
            throw new BizException("订单用户画像查询异常");
        }
        List<PieChartVo> ageDistribution = new ArrayList<>();
        for (Map<String, Object> map : ageDistributionList) {
            Object obj = map.get("key");
            String key = obj == null ? null : obj.toString();
            obj = map.get("value");
            Integer value = obj == null ? 0 : Integer.parseInt(String.valueOf(obj));
            ageDistribution.add(new PieChartVo(key, value));
        }
        result.setAgeDistribution(ageDistribution);

        return result;
    }




    /**
     * 订单统计环比
     *
     * @param orderType
     * @return
     */
    private OrderProportion getOrderProportion(StatisticsOrderTypeEnum orderType) {
        OrderProportion orderProportion = new OrderProportion();
        // 近七天本期数量
        Integer sevenBcount = 0;
        // 近七天上期数量
        Integer sevenScount = 0;
        // 近三十天本期数量
        Integer thirtyBcount = 0;
        // 近三十天上期数量
        Integer thirtyScount = 0;

        if (orderType.equals(StatisticsOrderTypeEnum.SUBSCRIBE)) {
            sevenBcount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.SUBSCRIBE, LocalDate.now().minusDays(7), LocalDate.now().minusDays(1));
            sevenScount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.SUBSCRIBE, LocalDate.now().minusDays(14), LocalDate.now().minusDays(8));

            thirtyBcount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.SUBSCRIBE, LocalDate.now().minusDays(30), LocalDate.now().minusDays(1));
            thirtyScount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.SUBSCRIBE, LocalDate.now().minusDays(60), LocalDate.now().minusDays(31));

        } else if (orderType.equals(StatisticsOrderTypeEnum.EXCLUSIVE)) {
            sevenBcount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.EXCLUSIVE, LocalDate.now().minusDays(7), LocalDate.now().minusDays(1));
            sevenScount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.EXCLUSIVE, LocalDate.now().minusDays(14), LocalDate.now().minusDays(8));

            thirtyBcount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.EXCLUSIVE, LocalDate.now().minusDays(31), LocalDate.now().minusDays(1));
            thirtyScount = basicdataStatisticsOrderService.getStatisticsOrderCountByDate(StatisticsOrderTypeEnum.EXCLUSIVE, LocalDate.now().minusDays(60), LocalDate.now().minusDays(31));

        }

        orderProportion.setSevenDayCount(sevenBcount);
        orderProportion.setThirtyDayCount(thirtyBcount);

        if (sevenScount == 0) {
            if (sevenBcount == 0) {
                orderProportion.setSevenDayProportion(sevenBcount + "%");
            } else {
                orderProportion.setSevenDayProportion("-");
            }
        } else {
            BigDecimal sevenProportionValue = BigDecimal.valueOf((sevenBcount - sevenScount) * 100).divide(BigDecimal.valueOf(sevenScount), 2, BigDecimal.ROUND_HALF_UP);
            orderProportion.setSevenDayProportion(sevenProportionValue + "%");
        }
        if (thirtyScount == 0) {
            if (thirtyBcount == 0) {
                orderProportion.setThirtyDayProportion(thirtyBcount + "%");
            } else {
                orderProportion.setThirtyDayProportion("-");
            }
        } else {
            BigDecimal thirtyProportionValue = BigDecimal.valueOf((thirtyBcount - thirtyScount) * 100).divide(BigDecimal.valueOf(thirtyScount), 2, BigDecimal.ROUND_HALF_UP);
            orderProportion.setThirtyDayProportion(thirtyProportionValue + "%");
        }

        return orderProportion;

    }


    /**
     * 违章统计
     *
     * @return
     */
    @Override
    public ViolationCountVo getViolationStatisticsVo() throws Exception {
        ViolationCountVo violationCountVo = null;

        ViolationCountDto violationCountDto = carViolationService.getViolationStatisticsDto();
        if (null == violationCountDto) {
            throw new Exception("查询失败");
        }
        violationCountVo = new ViolationCountVo();

        BeanUtils.copyProperties(violationCountDto, violationCountVo);

        //违章数量饼状图
        if (null != violationCountDto.getViolationCountPieDto() && violationCountDto.getViolationCountPieDto().size() > 0) {
            List<PieChartVo> violationCountPieVo = new ArrayList<>();
            PieChartVo pieChartVo = null;
            for (PieChartDto pieChartDto : violationCountDto.getViolationCountPieDto()) {
                pieChartVo = new PieChartVo();
                BeanUtils.copyProperties(pieChartDto, pieChartVo);
                violationCountPieVo.add(pieChartVo);
            }
            violationCountVo.setViolationCountPieVo(violationCountPieVo);
        }

        //违章分数饼状图
        if (null != violationCountDto.getViolationFractionPieDto() && violationCountDto.getViolationFractionPieDto().size() > 0) {
            List<PieChartVo> violationFractionPieVo = new ArrayList<>();
            PieChartVo pieChartVo = null;
            for (PieChartDto pieChartDto : violationCountDto.getViolationFractionPieDto()) {
                pieChartVo = new PieChartVo();
                BeanUtils.copyProperties(pieChartDto, pieChartVo);
                violationFractionPieVo.add(pieChartVo);
            }
            violationCountVo.setViolationFractionPieVo(violationFractionPieVo);
        }

        //违章罚款金额线形图
        if (null != violationCountDto.getViolationFineFeePieDto() && violationCountDto.getViolationFineFeePieDto().size() > 0) {
            List<PieChartVo> violationFineFeePieVo = new ArrayList<>();
            PieChartVo pieChartVo = null;
            for (PieChartDto pieChartDto : violationCountDto.getViolationFineFeePieDto()) {
                pieChartVo = new PieChartVo();
                BeanUtils.copyProperties(pieChartDto, pieChartVo);
                violationFineFeePieVo.add(pieChartVo);
            }
            violationCountVo.setViolationFineFeePieVo(violationFineFeePieVo);
        }

        return violationCountVo;
    }

    /**
     * 待处理事务统计
     *
     * @return
     */
    @Override
    public PendStatisticsVo getPendStatisticsVo() {

        PendStatisticsVo pendStatisticsVo = new PendStatisticsVo();

        //车辆待处理数量
        CarPendStatisticsDto carPendStatisticsDto = carBizService.getCarPendStatisticsDto();
        BeanUtils.copyProperties(carPendStatisticsDto, pendStatisticsVo);

        //订单待处理数量
        OrderPendCountDto orderPendCountDto = orderBizService.getOrderPendCountDto();
        pendStatisticsVo.setSubscribeReviewed(orderPendCountDto.getSubscribeReviewed());
        pendStatisticsVo.setExclusiveReviewed(orderPendCountDto.getExclusiveReviewed());

        //库存待处理数量 广
        pendStatisticsVo.setVehicleWaitingStorage(stockCarService.getCount(StockCarStatusEnum.WAIT_STOCK.getValue(), StockCarStockTypeEnum.ENTREPOT_STORAGE.getValue()).intValue());

        //商家待处理数量 辉
        Map<String, Object> storeMap = new HashMap<>();
        storeMap.put("verifyStatus", StoreVerifyStatusEnum.UN_VERIFY.getValue());
        pendStatisticsVo.setStoreEntryReviewed(storeService.getStoreCount(storeMap));

        //用户待处理数量 广
        pendStatisticsVo.setDriverLicenseReviewed(drivingLicenseService.getDrivingLicenseCountBystatus(DrivingLicenseStatusEnum.WAIT_PASS.getValue()).intValue());
        pendStatisticsVo.setComplaintPending(complaintService.getCountByStatus(ComplaintStatusEnum.UNTREATED.getValue()).intValue());

        //财务待处理数量 辉
        Map<String, Object> repaymentMap = new HashMap<>();
        repaymentMap.put("auditStatus", OfflineAuditStatusEnum.UNREVISED.getValue());
        pendStatisticsVo.setRepaymentReviewed(offlineService.getOfflineCount(repaymentMap));


        return pendStatisticsVo;
    }

    @Override
    public RiskStatisticsVo getRiskStatisticsVo() {
        RiskStatisticsVo riskStatisticsVo = new RiskStatisticsVo();

        //订阅超程订单
        riskStatisticsVo.setSubscribeOverride(Integer.valueOf(redisUtil.get(SUBSCRIBE_OVERRIDE)));

        //专属超程订单
        riskStatisticsVo.setExclusivelOverride(Integer.valueOf(redisUtil.get(EXCLUSIVE_OVERRIDE)));

        //订阅超时未还车
        riskStatisticsVo.setSubscribeOvertime(Integer.valueOf(redisUtil.get(SUBSCRIBE_OVERTIME)));

        //专属超时未还车
        riskStatisticsVo.setExclusivelOvertime(Integer.valueOf(redisUtil.get(EXCLUSIVE_OVERTIME)));

        //逾期未还订单
        riskStatisticsVo.setOverdueOrders(Integer.valueOf(redisUtil.get(OVERDUE_ORDERS)));


        //失联车量（参数不传则查询全部车辆）
        List<IovCarOfflineAlarm> iovCarOfflineAlarmList = iovCarService.listOfflineAlarmsByVin(null, null, null,null);
        if (null == iovCarOfflineAlarmList || iovCarOfflineAlarmList.size() <= 0) {
            riskStatisticsVo.setLostVehicle(0);
        } else {
            riskStatisticsVo.setLostVehicle(iovCarOfflineAlarmList.size());
        }

        return riskStatisticsVo;
    }

    @Override
    public AssetCountVo getAssetCount() {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(1);
        Map<Integer, Integer> statisticsAssetCount = statisticsAssetService.getStatisticsAssetCount(localDateTime);
        return Convert.toAssetCountVo(statisticsAssetCount);
    }


}
